//
//  WHUpdateVersionViewController.m
//  WHPersonalData
//
//  Created by mac on 2018/5/28.
//  Copyright © 2018年 mac. All rights reserved.
//

#define  FBKeyWindow   ((AppDelegate *)[UIApplication sharedApplication].delegate).window

#import "WHUpdateVersionViewController.h"
#import "WHUpdateVersionView.h"
#import "AppDelegate.h"

@interface WHUpdateVersionViewController ()<WHUpdateVersionViewDelegate>

@property (nonatomic,assign)BOOL  isDebug;        //上架时要修改

@end

@implementation WHUpdateVersionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor whiteColor];
    self.title  =@"更新版本";
    [self setUpUpdateVersionView];
    self.isDebug = YES;
 
}

-(void)setUpUpdateVersionView
{
    WHUpdateVersionView*updateVersionView =[[WHUpdateVersionView alloc]initWithFrame:CGRectMake(0,nevagationHeight, ScreenW, ScreenH-nevagationHeight)];
     updateVersionView.delegate = self;
    [self.view addSubview:updateVersionView];
}

-(void)updateVersionViewButtonClick:(UIButton *)button
{
    if (button.tag ==200)
    {
      //返回
      [self.navigationController popViewControllerAnimated:YES];
    }else if (button.tag ==201)
    {
        //立即更新
        #ifdef UNRELEASE
        // 配置蒲公英链接
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.pgyer.com/CVVDh8mh"] options:@{} completionHandler:nil];
        #else
        // 配置appstore链接
        NSURL* url = [NSURL URLWithString:@"https://itunes.apple.com/us/app/wei-gang/id1399479402?l=zh&ls=1&mt=8"];
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
                if (success) {
                    // URL成功打开
                } else {
                    // 处理URL打开失败的情况
                }
            }];
        } else {
            // 对于iOS 10以下版本，继续使用openURL:
            [[UIApplication sharedApplication] openURL:url];
        }
        #endif
       // [self exitAppWithViewController:self];
    }
}
//点击“是”确定按钮后，使用动画效果退出用于程序
- (void)exitAppWithViewController:(UIViewController *)viewcontroller
{
    //退出程序
    [UIView animateWithDuration:0.3f animations:^{
        FBKeyWindow.alpha = 0.1;
        FBKeyWindow.transform = CGAffineTransformMakeScale(0.1, 0.1);
    } completion:^(BOOL finished) {
        exit(0);
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
